﻿Imports DevExpress.Utils
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Namespace IControls
    Public Class IDateEdit
        Inherits DateEdit
        ' Methods
        Public Sub New()
            MyBase.SetStyle(ControlStyles.UserPaint, True)
            MyBase.UpdateStyles()
            Me.EnterMoveNextControl = True
            MyBase.Properties.AllowNullInput = DefaultBoolean.True
            MyBase.Properties.DisplayFormat.FormatType = FormatType.DateTime
            MyBase.Properties.DisplayFormat.FormatString = "dd/MM/yyyy"
            MyBase.Properties.EditMask = "dd/MM/yyyy"
            Me.EditValue = Nothing
            MyBase.Properties.Mask.UseMaskAsDisplayFormat = True
            Me.BorderStyle = BorderStyles.NoBorder
            Me.Properties.AllowDropDownWhenReadOnly = DefaultBoolean.False
            Me.InitializeComponent()
        End Sub
        Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
            MyBase.OnPaint(pe)
            ControlPaint.DrawBorder(pe.Graphics, pe.ClipRectangle, MyBase.Parent.BackColor, 0, ButtonBorderStyle.Solid, MyBase.Parent.BackColor, 0, ButtonBorderStyle.Solid, MyBase.Parent.BackColor, 0, ButtonBorderStyle.Solid, Color.Black, 1, ButtonBorderStyle.Dotted)
        End Sub
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If (disposing AndAlso (Not Me.components Is Nothing)) Then
                Me.components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

        Private Sub InitializeComponent()
            Me.fProperties = New DevExpress.XtraEditors.Repository.RepositoryItemDateEdit()
            CType(Me.fProperties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.fProperties.VistaTimeProperties, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'fProperties
            '
            Me.fProperties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.fProperties.Name = "fProperties"
            Me.fProperties.VistaTimeProperties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton()})
            '
            'IDateEdit
            '
            Me.EnterMoveNextControl = True
            CType(Me.fProperties.VistaTimeProperties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.fProperties, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub

        Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
            MyBase.OnGotFocus(e)
            Me.i = 0
        End Sub

        Protected Overrides Sub OnKeyUp(ByVal e As KeyEventArgs)
            If (((((e.KeyCode = Keys.D0) OrElse (e.KeyCode = Keys.D1)) OrElse ((e.KeyCode = Keys.D2) OrElse (e.KeyCode = Keys.D3))) OrElse (((e.KeyCode = Keys.D4) OrElse (e.KeyCode = Keys.D5)) OrElse ((e.KeyCode = Keys.D6) OrElse (e.KeyCode = Keys.D7)))) OrElse (((((e.KeyCode = Keys.D8) OrElse (e.KeyCode = Keys.D9)) OrElse ((e.KeyCode = Keys.NumPad0) OrElse (e.KeyCode = Keys.NumPad1))) OrElse (((e.KeyCode = Keys.NumPad2) OrElse (e.KeyCode = Keys.NumPad3)) OrElse ((e.KeyCode = Keys.NumPad4) OrElse (e.KeyCode = Keys.NumPad5)))) OrElse (((e.KeyCode = Keys.NumPad6) OrElse (e.KeyCode = Keys.NumPad7)) OrElse ((e.KeyCode = Keys.NumPad8) OrElse (e.KeyCode = Keys.NumPad9))))) Then
                Me.i += 1
            End If
            If (Me.i = 2) Then
                If (MyBase.SelectionStart = 0) Then
                    Me.i = 0
                    MyBase.Select(3, 2)
                    Return
                End If
                If (MyBase.SelectionStart = 3) Then
                    Me.i = 0
                    MyBase.Select(6, 4)
                End If
            End If
            MyBase.OnKeyUp(e)
        End Sub


        ' Fields
        Private components As IContainer
        Friend WithEvents fProperties As DevExpress.XtraEditors.Repository.RepositoryItemDateEdit
        Private i As Integer
    End Class
End Namespace

